﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Sayook.Framework.TemplateApi.Controllers
{
    /// <summary>
    /// 测试
    /// </summary>
    [Route("[controller]/[action]")]
    [Authorize]
    [ApiController]
    public class TestController : ControllerBase
    {
        /// <summary>
        /// 测试接口
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult Get()
        {
            return Ok("ok");
        }

        /// <summary>
        /// 测试状态
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public ActionResult<int> ShowStatusCode(int id)
        {
            switch (id)
            {
                case 400:
                    return NotFound();

                case 401:
                    return BadRequest();

                default:
                    return Ok(10 / id);
            }
        }

        /// <summary>
        /// 模拟登录
        /// </summary>
        /// <param name="user">用户信息</param>
        /// <returns></returns>
        [HttpPost, HttpGet]
        public ActionResult<UserInfo> Login(UserInfo user)
        {
            return new ActionResult<UserInfo>(user);
        }
    }
}